package com.java.sample.domain.bak;

import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;

public class LDAPDomainQuery {
    public static void main(String[] args) {
        Hashtable<String, String> env = new Hashtable<>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://your.domain.controller:389");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "username@domain"); // 域账号
        env.put(Context.SECURITY_CREDENTIALS, "password"); // 密码

        try {
            DirContext ctx = new InitialDirContext(env);

            // 查询当前用户信息
            Attributes attrs = ctx.getAttributes("");
            System.out.println("User attributes: " + attrs);

            ctx.close();
        } catch (NamingException e) {
            System.err.println("LDAP error: " + e.getMessage());
        }
    }
}